// userPageC/pages/userPersonal/walletSize/walletSize.js
const app = getApp()
const WXAPI = require("../../../../api/api")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userData:{},
    walletData: {},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setNavSize()
    this.getuserInfo()
    this.getuserWalletInfo()
  },
  //返回上一级
  handleBack(){
    wx.navigateBack({
      delta: 1
    });
  },
  //获取用户信息
  getuserInfo(){
    WXAPI.userInfo('', (res) =>{
      console.log("切换商家版",res.result)
      if(res.code === 200){
        app.globalData.nickName = res.result.nickName
        this.setData({
          userData:res.result
        })
      }
    })
  },
  //钱包二维码
  getuserWalletInfo(){
    WXAPI.userWalletInfo('', (res) =>{
      console.log("钱包二维码",res.result)
      if(res.code === 200){
        app.globalData.nickName = res.result.nickName
        this.setData({
          walletData:res.result
        })
      }
    })
  },
  //明细
  handleBalance(){
    wx.navigateTo({
      url: '/userPageC/pages/userPersonal/balanceList/balanceList',
    })
  },
  //提现
  handleWithdrawal(){
    wx.navigateTo({
      url: '/userPageC/pages/userPersonal/withdrawal/withdrawal',
    })
  },

  copy(){ //复制
    wx.setClipboardData({
      data: this.data.walletData.accountAddress,
      success (res) {
        wx.showToast({
          title: '复制成功',
        })
      }
    })    
  },
  // 通过获取系统信息计算导航栏高度
  setNavSize: function() {
    var that = this
        , sysinfo = wx.getSystemInfoSync()
        , statusHeight = sysinfo.statusBarHeight
        , isiOS = sysinfo.system.indexOf('iOS') > -1
        , navHeight;
    if (!isiOS) {
        navHeight = 48;
    } else {
        navHeight = 44;
    }
    console.log('statusHeight',statusHeight)
    console.log('navHeight',navHeight)
    that.data.top = statusHeight + navHeight
    that.setData({
        status: statusHeight,
        navHeight: navHeight
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})